﻿#include "mDlgTest2.h"
#include "ui_mDlgTest2.h"
#include <QPainter>
#include <QColor>
#include "stable.h"




mDlgTest2::mDlgTest2(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::mDlgTest2)
{
    ui->setupUi(this);

    //---0定时器
    QTimer* pTimer = new QTimer(this);
    {
        pTimer->start(500);
        static int nMove = 0;
        nMove +=10;
        connect(pTimer, &QTimer::timeout,
                [=]()
        {
            update(nMove);
        });
    }


}


void mDlgTest2::paintEvent(QPaintEvent *event)
{
    //---创建绘制器
    QPainter painter(this);
    QPen TempPen= painter.pen();
    TempPen.setWidth(4);
    painter.setPen(TempPen);


    //---绘制对话框北京
     QRect  TempRect = this->rect();
     TempRect = event->rect();
     painter.drawPixmap(TempRect, QPixmap(":/Jpg/Icon.jpg"));


     //---绘制白色底色
//     QBrush TempBrush   = painter.brush();

//     painter.fillRect(TempRect,QColor(255,255,255));
//     TempPen.setColor(QColor(0,0,0));
//     painter.setPen(TempPen);
//     painter.drawRect(TempRect);




    //---绘制椭圆
    TempPen.setColor(QColor(255,0,0));
    painter.setPen(TempPen);
    painter.drawEllipse(QPoint(100, 60), 80 ,40);


    //---设置抗锯齿 效率变低
    TempPen.setColor(QColor(0,255,0));
    painter.setPen(TempPen);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.drawEllipse(QPoint(400, 150), 50 ,100);


    //---绘制矩形
    TempPen.setColor(QColor(255,0,255));
    painter.setPen(TempPen);
    painter.translate(100, 100);
    painter.drawRect(QRect(20, 20, 50, 50));

    TempPen.setColor(QColor(0,255,0));
    painter.setPen(TempPen);
    painter.translate(100, 100);
    painter.drawRect(QRect(20, 20, 50, 50));

    TempPen.setColor(QColor(0,0,255));
    painter.setPen(TempPen);
    painter.translate(100, 100);
    painter.drawRect(QRect(20, 20, 50, 50));

}


void mDlgTest2::update(int nMove)
{

    QPainter painter(this);
    QPicture pic;
    pic.load(":/Jpg/Icon.jpg");
    painter.drawPicture(0+nMove, 0, pic);
}


mDlgTest2::~mDlgTest2()
{
    delete ui;
}
